/**
 * Created by wxb on 2016/11/4.
 */
'use strict';

angular.module('BlurAdmin')
  .factory('myPrefixUrl', function (publicFunc, localStorageService) {
    var imageData = localStorageService.get('imageData');
    var videoData = localStorageService.get('videoData');
    var cooperationData = localStorageService.get('cooperationData');

    var prefix = '/kt/admin/';
    var url = {
      image_: {
        url: 'config',
        method: 'GET',
        data: imageData
      },
      video_: {
        url: 'config',
        method: 'GET',
        data: videoData
      },
      cooperation_: {
        url: 'config',
        method: 'GET',
        data: cooperationData
      },

    };
    return publicFunc.urlAddPrefix(url, prefix);
  })
  .service('myPrefixService', function (httpService, myPrefixUrl, localStorageService) {
    this.imagePrefix = function () {
      return httpService.http({}, myPrefixUrl.image_, {}).then(function (data) {
        if (data && data.errcode === 0 ) {
          localStorageService.set('imageData', data.data.staticRes.resourceUrl);
          return data.data.host;
        }
        else {
          return data
        }
      })
    };
    this.videoPrefix = function () {
      return httpService.http({}, myPrefixUrl.video_, {}).then(function (data) {
        if (data && data.errcode === 0 ) {
          localStorageService.set('videoData', data.data.staticRes.resourceUrl);
          return data.data.host;
        }
        else {
          return data
        }
      })
    };
    this.cooperationPrefix = function () {
      return httpService.http({}, myPrefixUrl.cooperation_, {}).then(function (data) {
        if (data && data.errcode === 0 ) {
          localStorageService.set('cooperationData', data.data.staticRes.resourceUrl);
          return data.data.host;
        }
        else {
          return data
        }
      })
    };






  });
